package com.xpxrule.controller.manage;

import com.xpxrule.dataobject.biz.model.ReturnResponse;
import com.xpxrule.dataobject.req.ConstantItemQueryReq;
import com.xpxrule.dataobject.vo.ConstantItemVo;
import com.xpxrule.service.ConstantItemService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/constantItem")
public class ConstantItemController {
    @Autowired
    private ConstantItemService constantItemService;

    /**
     * 新增常量明细项
     * @param vo
     * @return
     */
    @PostMapping("/insert")
    public ReturnResponse<Integer> insert(@RequestBody ConstantItemVo vo) {
        return constantItemService.insert(vo);
    }

    /**
     * 根据id删除常量明细项
     * @param id
     * @return
     */
    @GetMapping("/delete/{id}")
    public ReturnResponse<Integer> delete(@PathVariable("id") Long id) {
        return constantItemService.delete(id);
    }

    /**
     * 根据id更新常量明细项
     * @param vo
     * @return
     */
    @PostMapping("/update")
    public ReturnResponse<Integer> update(@RequestBody ConstantItemVo vo) {
        return constantItemService.update(vo);
    }

    /**
     * 根据查询条件查询常量明细项
     * @param req
     * @return
     */
    @PostMapping("/select/byQuery")
    public ReturnResponse<List<ConstantItemVo>> selectList(@RequestBody ConstantItemQueryReq req) {
        return constantItemService.selectList(req);
    }

    /**
     * 根据常量key查询常量明细项列表
     * @param constantKey
     * @return
     */
    @GetMapping("/select/constantItem/by/{constantKey}")
    public ReturnResponse<List<ConstantItemVo>> selectConstantItemVoByConstantKey(@PathVariable("constantKey") String constantKey) {
        return constantItemService.selectListByConstantKey(constantKey);
    }
}
